<form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off" >

    <div class="layui-card-body" style="height:250px">        
        <div class="layui-form-item">
            <label class="layui-form-label">打包状态</label>
            <div class="layui-input-block">
	            <select class="layui-select" name="pack" required lay-filter="pack">
	            	<option value="">请选择打包状态</option>
	                {foreach $pack as $k=>$v}
	                	<option value="{$k}">{$v}</option>
	                {/foreach}
	            </select>
            </div>
        </div>
        <div class="layui-form-item pack_box" style="display: none">
            <label class="layui-form-label">打包者姓名</label>
            <div class="layui-input-block">
                <select class="layui-select" name="pack_name" required>
	            	<option value="">请选择打包者姓名</option>
	                {foreach $pack_name as $k=>$v}
	                	<option value="{$k}">{$v}</option>
	                {/foreach}
	            </select>
            </div>
        </div>
        <div class="layui-form-item pack_box" style="display: none">
            <label class="layui-form-label">打包日期</label>
            <div class="layui-input-block">
                <input data-date-input="" name="pack_at" value="" 
                placeholder="请选择打包日期" required 
                class="layui-input" autocomplete="off">
            </div>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='ids'}<input type='hidden' value='{$ids}' name='ids'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存</button>
        <button class="layui-btn layui-btn-danger" type='button' data-close>取消</button>
    </div>
    <script>
    	window.form.render();
    	form.on('select(pack)', function(data){
      
	        console.log(data.value); //得到被选中的值
	        if(data.value==2){
	        	$(".pack_box").show(); 
	        	$("[name='pack_name']").attr("required",'required');
	        	$("[name='pack_at']").attr("required",'required'); 
	        }else{
	        	$(".pack_box").hide();        	
	            $("[name='pack_name']").removeAttr("required");
	            $("[name='pack_name']").val("");
	            $("[name='pack_at']").removeAttr("required");
	            $("[name='pack_at']").val("");
	        }
	        form.render();
	    });
    </script>
</form>
